package com.dao.rxjava01.uis.activities;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.view.View;
import android.widget.Toast;

import com.dao.green.cn.applibary.uis.BaseActivity;
import com.dao.rxjava01.R;
import com.dao.rxjava01.beans.PeopleBean;
import com.dao.rxjava01.beans.UserBean;
import com.dao.rxjava01.databinding.AcDemo01Binding;

import java.util.Random;

/**
 * Created by Ant on 2017/7/6  17:55
 * <p>
 * <p>
 *
 * @version 1.0.0
 * @auther Ant
 */

public class Demo01 extends BaseActivity {
    private AcDemo01Binding binding;
    private Demo01Presenter presenter;
    private PeopleBean people;

    @Override
    public void bindLayout() {
        binding = DataBindingUtil.setContentView(this, R.layout.ac_demo01);
        presenter = new Demo01Presenter(this);
        binding.setPresenter(presenter);
    }

    @Override
    public void initView() {

    }

    @Override
    public void initData() {
        UserBean user = new UserBean();
        user.setId(123123l);
        user.setName("Ant");
        user.setPasss("antPassword");
        user.setAge(25);
        user.setTelphone("13661326433");
        binding.setUser(user);
        people = new PeopleBean();
        people.setId(123123l);
        people.setName("peopleName");
        people.setTelphone("tel:135523423423");
        binding.setPeople(people);

    }

    @Override
    public void initListener() {

    }


    // listener class
    public class Demo01Presenter implements View.OnClickListener {
        private Context context;

        public Demo01Presenter(Context context) {
            this.context = context;
        }


        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.ac_demo01_obt_text:
                    Toast.makeText(context, "obt clicked", Toast.LENGTH_SHORT).show();
                    break;
                case R.id.ac_demo01_obt_changeData:
                    Random random=new Random();
                    int i = random.nextInt(100);
                    people.setId(0l+i);
                    people.setName("name"+i);
                    people.setTelphone("tel:1234"+i);
                    break;
            }
        }

        public void click(UserBean user) {
            Toast.makeText(context, "datat=" + user.toString(), Toast.LENGTH_SHORT).show();
        }
    }

}
